package com.love.marriage.userRechargeRecordInfo.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.love.marriage.userRechargeRecordInfo.entity.UserRechargeRecordInfo;
import com.love.marriage.userRechargeRecordInfo.mapper.UserRechargeRecordInfoMapper;
import com.love.marriage.userRechargeRecordInfo.service.UserRechargeRecordInfoService;
import com.love.marriage.userRechargeRecordInfo.vo.UserRechargeRecordInfoPageVo;
import com.love.marriage.userRechargeRecordInfo.vo.UserRechargeRecordInfoVo;
import com.love.marriage.utils.StringUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
 * <p>
 * description:  充值记录表服务实现类
 * author:       mybatisPlus
 * createDate:   2024-10-16 23:06:22
 * version:      1.0.0
 */
@Service
@RequiredArgsConstructor
public class UserRechargeRecordInfoServiceImp extends ServiceImpl<UserRechargeRecordInfoMapper, UserRechargeRecordInfo> implements UserRechargeRecordInfoService {

    private final UserRechargeRecordInfoMapper userRechargeRecordInfoMapper;

    @Override
    public Page<UserRechargeRecordInfoPageVo> getPage(Long pageNum, Long pageSize, UserRechargeRecordInfoVo userRechargeRecordInfoVo) {
        Page<UserRechargeRecordInfoVo> page = new Page<>(pageNum == null ? 1 : pageNum, pageSize == null ? 10 : pageSize);
        return userRechargeRecordInfoMapper.getPage(page, userRechargeRecordInfoVo);
    }

    @Override
    public UserRechargeRecordInfoVo queryUserRechargeRecordInfo(Long id) {
        return userRechargeRecordInfoMapper.queryUserRechargeRecordInfo(id);
    }

    @Override
    public UserRechargeRecordInfoVo addUserRechargeRecordInfo(UserRechargeRecordInfoVo userRechargeRecordInfoVo) {
        UserRechargeRecordInfo userRechargeRecordInfo = new UserRechargeRecordInfo();
        BeanUtils.copyProperties(userRechargeRecordInfoVo, userRechargeRecordInfo);
        userRechargeRecordInfoMapper.insert(userRechargeRecordInfo);
        UserRechargeRecordInfoVo res = new UserRechargeRecordInfoVo();
        userRechargeRecordInfo.setStatus(true);
        BeanUtils.copyProperties(userRechargeRecordInfo, res);
        return res;
    }

    @Override
    public UserRechargeRecordInfoVo updateUserRechargeRecordInfo(UserRechargeRecordInfoVo userRechargeRecordInfoVo) {
        UserRechargeRecordInfo userRechargeRecordInfo = new UserRechargeRecordInfo();
        BeanUtils.copyProperties(userRechargeRecordInfoVo, userRechargeRecordInfo);
        userRechargeRecordInfoMapper.updateById(userRechargeRecordInfo);
        return userRechargeRecordInfoVo;
    }

    @Override
    public Boolean deleteUserRechargeRecordInfo(String ids) {
        if(StringUtils.isEmpty(ids)) {
            return true;
        }
        List<String> idArr = Arrays.asList(ids.split(","));
        userRechargeRecordInfoMapper.deleteBatchIds(idArr);
        return true;
    }
}
